using System;
using UnityEngine;

[Serializable]
public class TTCameraBehaviourPrepareForAction : TTCameraBehaviour
{
	public Vector3 initialPosOffsetFromBallAtStart;

	public Vector3 finalPosOffsetFromBallAtStart;

	public Vector3 initialRotation;

	public Vector3 finalRotation;

	public float waitMovementSensitivity;

	private Transform waitTransform;

	private bool isWaitDone;

	private Vector3 positionAtWaitDone = Vector3.zero;

	private Vector3 waitPosition = Vector3.zero;

	public override void Start(Camera cam, TTCameraController camController, TTCameraOptions cameraOptions)
	{
		base.Start(cam, camController, cameraOptions);
		waitTransform = null;
		isWaitDone = false;
	}

	private void SetWaitTransformAtStart(Transform waitTransform)
	{
		this.waitTransform = waitTransform;
		waitPosition = waitTransform.position;
	}

	private void WaitDone()
	{
		isWaitDone = true;
		positionAtWaitDone = waitTransform.position;
	}

	public override void Update()
	{
		if (!(waitTransform == null))
		{
			if (!isWaitDone)
			{
				UpdateIntoWaitPosition();
			}
			else
			{
				UpdateAfterStartAction();
			}
			camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, fov, RealTime.deltaTime * rotationSpeed);
		}
	}

	private void UpdateIntoWaitPosition()
	{
		if ((waitTransform.position - waitPosition).magnitude >= waitMovementSensitivity)
		{
			waitPosition = waitTransform.position;
		}
		camera.transform.position = Vector3.Lerp(camera.transform.position, waitPosition + initialPosOffsetFromBallAtStart, RealTime.deltaTime * moveSpeed);
		camera.transform.rotation = Quaternion.Lerp(camera.transform.rotation, Quaternion.Euler(initialRotation), RealTime.deltaTime * rotationSpeed);
	}

	private void UpdateAfterStartAction()
	{
		camera.transform.position = Vector3.Lerp(camera.transform.position, positionAtWaitDone + finalPosOffsetFromBallAtStart, RealTime.deltaTime * moveSpeed);
		camera.transform.rotation = Quaternion.Lerp(camera.transform.rotation, Quaternion.Euler(finalRotation), RealTime.deltaTime * rotationSpeed);
	}
}
